clear;clc;

%% Set AWG
awg=EquipmentControl.AWG.TektronixAFG3252('visa-usb',  'USB0::0x0699::0x034E::B010598::0::INSTR');
awg.setWaveFrequency(1, 500.0).setWaveShape(1, 'SIN');
awg.setBurstCycle(1, 4);
awg.fire(1).wait();


%% Set DAQ
ni = EquipmentControl.NIDAQ.NIUSB6366('dev1a');

ni.addInputChannel(0);
ni.addInputChannel(1);
ni.addExternalTrigger('PFI0', 'StartTrigger');
ni.setSampling(0.01, 50000);
% ni.addlistener();

%% Data Aquisition
for freq=500:510
    awg.setWaveFrequency(1, freq);
    ni.startBackground();
    awg.forceTrigger();
    ni.wait();
end

%% Plot
[X,Y] = meshgrid(ni.time(:, 1), 50:60);
Z = ni.data.';

subplot(1,2,1)
contourf(X, Y, Z(1:2:end,:), 100, 'LineStyle' , 'none');
subplot(1,2,2)
contourf(X, Y, Z(2:2:end,:), 100, 'LineStyle' , 'none');

%% Clean
awg.silence(1);
awg.disconnect_device();
